/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 25228
 * Date: 2024-08-01
 * Time: 15:47
 */
public class Solution2 {
    public boolean chkPalindrome(ListNode A) {
        ListNode fast=A;
        ListNode slow=A;
        while(fast!=null&&fast.next!=null){
            fast=fast.next.next;
            slow=slow.next;
        }
        ListNode cur=slow.next;
        slow.next=null;
        while(cur!=null){
            ListNode curn=cur.next;
            cur.next=slow;
            slow=cur;
            cur=curn;
        }
        fast=A;
        while(fast!=slow){
            if(fast.val!=slow.val){
                return false;
            }
            if(fast.next==slow){
                return true;
            }
            fast=fast.next;
            slow=slow.next;
        }
        return true;
    }
}
